package com.example.xui;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.xui.BlankFragment.BlankFragment;
import com.example.xui.BlankFragment.BlankFragment2;
import com.example.xui.BlankFragment.BlankFragment6;
import com.example.xui.Way.Typefaces;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.xuexiang.xui.XUI;
import com.xuexiang.xui.widget.tabbar.EasyIndicator;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {
    private List<Fragment> list;
    private String[] tab={"注册","快捷登录","密码登录"};
    private FragmentManager manager;
    private MyFragmentPageAdapter adapter;
    private SystemBarTintManager tintManager;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XUI.initTheme(this);
        x.Ext.init(getApplication());
        setContentView(R.layout.activity_main2);
        Window window =this.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(this,R.color.colorPrimaryDark));
        changStatusIconCollor(true);
  /*      TextView tv = findViewById(R.id.tv_title);
       // TextView textView=findViewById(R.id.textView9);
        tv.setTypeface(Typefaces.get(this, "Light.ttf"));*/
      //  textView.setTypeface(Typefaces.get(this,"Satisfy-Regular.ttf"));
      //  new Titanic().start(tv);
        list = new ArrayList<Fragment>();
        BlankFragment f1 = new BlankFragment();
        BlankFragment2 f2 = new BlankFragment2();
        BlankFragment6 f3=new BlankFragment6();
        list.add(f1);
        list.add(f3);
        list.add(f2);
        manager = getSupportFragmentManager();
        adapter = new MyFragmentPageAdapter(manager);
        EasyIndicator easyIndicator=findViewById(R.id.easy_indicator);
        easyIndicator.setTabTitles(tab);
        ViewPager viewPager=findViewById(R.id.view_pager1);
        easyIndicator.setViewPager(viewPager,adapter);
    }
    public void changStatusIconCollor(boolean setDark) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            View decorView = getWindow().getDecorView();
            if(decorView != null){
                int vis = decorView.getSystemUiVisibility();
                if(setDark){
                    vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                } else{
                    vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                }
                decorView.setSystemUiVisibility(vis);
            }
        }
    }
    class MyFragmentPageAdapter extends FragmentPagerAdapter {

        public MyFragmentPageAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub
            return list.get(arg0);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tab[position];
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return list.size();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            // TODO Auto-generated method stub
            super.destroyItem(container, position, object);
        }

    }

}
